package com.andy.blog.admin.controller;

import com.andy.blog.admin.dto.login.CaptchaDTO;
import com.andy.blog.admin.service.CaptchaBusService;
import com.andy.blog.common.reponse.GeneralResponseResult;
import com.andy.blog.dal.vo.EmailCaptchaVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 验证码操作处理
 * Created by andy on 2023-04-05 11:38
 */
@RestController
public class CaptchaController {

    @Resource
    private CaptchaBusService captchaBusService;

    /**
     * 生成验证码
     */
    @GetMapping("/captchaImage")
    public GeneralResponseResult<CaptchaDTO> getCaptchaImage() {
        return GeneralResponseResult.success(captchaBusService.getCaptchaImage());
    }

    /**
     * 根据邮箱获取验证码
     */
    @PostMapping("/portal/sendEmailByCode")
    public GeneralResponseResult<String> sendEmailByCode(@RequestBody EmailCaptchaVO emailCaptchaVO) {
        String uuid = captchaBusService.sendEmailByCode(emailCaptchaVO);
        return GeneralResponseResult.success(uuid);
    }
}
